#include<iostream>
#include<cmath>
#include<string.h>
using namespace std;
static int l = 0;
void sequence(int *a) {
	int i, j, n = 0;
	for (i = 0; i <= l - 1; i++) {
		for (j = 0; j < l - 1 - i; j++) {
			if (a[j] > a[j + 1]) {
				n = a[j];
				a[j] = a[j + 1];
				a[j + 1] = n;
			}
		}
	}

}

int find(int *a, int b) {
	int left = 0;
	int right = l - 1;
	while (left <= right) {
		{
			int mid = (left + right) / 2;
			if (a[mid] == b) {
				return mid;
			} else  if (a[mid] < b) {
				left = mid + 1;
			} else {
				right = mid - 1;
			}
		}
	}
	return -1;
}
int main() {
	int a[110], b[110];
	int i, n = 5;
	for (i = 0;; i++) {
		cin >> a[i];
		l++;
		if (a[i] == -9999)
			break;
	}
	l = l - 1;
	sequence(a);
	for (i = 0; i < n; i++) {
		cin >> b[i];
		cout << find(a, b[i]) << endl;
	}
}
